<?php
class Scrap_model extends CI_Model {

	function saveTitle() {
		$username = $this->session->userdata('username');
		$password = $this->session->userdata('password');
		$title = $this->input->post('title');
		$desc = $this->input->post('description');
		$tag = $this->input->post('tag');
		$urlpath = $this->input->post('q');

		$url = "http://localhost:8080/moms-diary/".$urlpath;
		$postFields = "&title=".$title."&description=".$desc."&tag=".$tag;
		$auth = $username.":".$password;
		$this->load->library('curl');
		$this->curl->create($url);
		$this->curl->options(array(
					CURLOPT_RETURNTRANSFER => true,
					CURLOPT_USERPWD => $auth, 
					CURLOPT_POST => count($postFields), 
					CURLOPT_HTTPHEADER => array("Content-type: application/x-www-form-urlencoded"), 
					CURLOPT_POSTFIELDS => $postFields
				));

		$returned_data = $this->curl->execute();

		echo $returned_data;
	}
	
	function saveScrap() {
		$username = $this->session->userdata('username');
		$password = $this->session->userdata('password');
		$image = $this->input->post('image');

		$url = "http://localhost:8080/moms-diary/services/picture/scrap";

		$auth = $username.":".$password;

		$this->load->library('curl');
		$this->curl->create($url);
		$this->curl->options(array(
					CURLOPT_RETURNTRANSFER => true,
					CURLOPT_USERPWD => $auth, 
					CURLOPT_POST => true, 
					CURLOPT_HTTPHEADER => array("Content-type: application/x-www-form-urlencoded"),
					CURLOPT_POSTFIELDS => urlencode($image)
				));
		
		//execute the API Call
		$returned_data = $this->curl->execute();
		$return =  $this->curl->info;
		if($returned_data){
			header("Content-type: application/json");
			print $returned_data;
		}
	}
}
